package com.yanqu.road.server.cmd.activity;


import com.yanqu.road.entity.activity.ActivityDisperseGoldInfo;
import com.yanqu.road.logic.pb.ActivityDisperseGoldPb;
import com.yanqu.road.pb.activity.ActivityDisperseGoldProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityDisperseGoldMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_ACTIVITY_DISPERSE_GOLD_REQ_PUSH, desc = "活动送财")
public class ActivityDisperseGoldCmd extends CrossCommand {

    ActivityDisperseGoldProto.CrossActivityDisperseGoldRespMsg respMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        respMsg = ActivityDisperseGoldProto.CrossActivityDisperseGoldRespMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ActivityDisperseGoldInfo goldInfo = ActivityDisperseGoldPb.parseToDisperseGoldInfo(respMsg.getGoldInfo());
        goldInfo.setServerId(serverId);
        ActivityDisperseGoldMgr.addActivityDisperseGoldInfo(goldInfo);

        ActivityDisperseGoldProto.CrossActivityDisperseGoldRespMsg.Builder respMsgBuilder = ActivityDisperseGoldProto.CrossActivityDisperseGoldRespMsg.newBuilder();
        respMsgBuilder.setActivityId(respMsg.getActivityId());
        respMsgBuilder.setGroupId(respMsg.getGroupId());
        respMsgBuilder.setGoldInfo(ActivityDisperseGoldPb.parseToDisperseGoldInfoTemp(goldInfo));
        YanQuMessage boradcastMsg = YanQuMessageUtils.buildMessage(Protocol.S_ACTIVITY_DISPERSE_GOLD_BORADCAST, respMsgBuilder);
        for(Long serverId : goldInfo.getServerList()){
            MessageHelper.sendPacket(serverId, 0, boradcastMsg);
        }
    }

    @Override
    public void sendData() {

    }
}
